import { http } from '@/utils/http.ts'
import type { CartItem } from '@/types/cart'

// 加入购物车
export const addCartApi = (data: { skuId: string; count: number }) => {
  return http({
    url: '/member/cart',
    method: 'POST',
    data,
  })
}

// 获取购物车列表
export const getCartListApi = () => {
  return http<CartItem[]>({
    url: '/member/cart',
    method: 'GET',
  })
}

// 删除购物车列表
export const deleteCartApi = (data: { ids: string[] }) => {
  return http({
    url: '/member/cart',
    method: 'DELETE',
    data,
  })
}

// 修改购物车商品
export const updateCartApi = (id: string, data: { count?: number; selected?: boolean }) => {
  return http({
    url: `/member/cart/${id}`,
    method: 'PUT',
    data,
  })
}

// 全选/取消全选
export const checkAllCartApi = (data: { selected: boolean }) => {
  return http({
    url: '/member/cart/selected',
    method: 'PUT',
    data,
  })
}
